﻿using UnityEditor;
using UnityEngine;

public class GroundShaderEditor : ShaderGUI
{

    private static int SID_GroundColors = Shader.PropertyToID("_GroundColors");
    public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
    {

        Material targetMat = materialEditor.target as Material;

        base.OnGUI(materialEditor, properties);

        EditorGUI.BeginChangeCheck();

        //for (int i = 0; i < 21; i++)
        //{
        //    var terrain = (TerrainType)i;
        //    var color = targetMat.GetColor("_Colors" + i);
        //    color = EditorGUILayout.ColorField(MapTexture.TerrainChinese[terrain], color);
        //    targetMat.SetColor("_Colors" + i, color);
        //    //targetMat.SetColor("_Colors" + i, MapTexture.TerrainGroundColors[terrain]);
        //    //EditorGUILayout.ColorField(MapTexture.TerrainChinese[terrain], 
        //    //    MapTexture.TerrainGroundColors[terrain]);
        //}
        var groundColors = Shader.GetGlobalVectorArray(SID_GroundColors);
        for (int i = 0; i < groundColors.Length; i++)
        {
            groundColors[i] = EditorGUILayout.ColorField(((TerrainType)i).ToString(), groundColors[i]);
        }
        Shader.SetGlobalVectorArray(SID_GroundColors, groundColors);
        //var colors = targetMat.GetColorArray(SID_GroundColors);
        //for (int i = 0; i < colors.Length; i++)
        //{
        //    colors[i] = EditorGUILayout.ColorField(((TerrainType)i).ToString(), colors[i]);
        //}
        //targetMat.SetColorArray(SID_GroundColors, colors);
        if (EditorGUI.EndChangeCheck())
        {


        }

    }

}